<?php	
	$fichierDonnees = fopen("../ressources/bddRatp.txt", "r");

	if($fichierDonnees){
		header('Content-Type: text/xml');
		$i = 0;
		$ligne = $_GET['ligne'];
		$stringLigne = "";
		while(($stringLigne = fgets($fichierDonnees)) !== false){
			if($i == $ligne)
				break;
			$i++;
		}
		fclose($fichierDonnees);
		$tab = explode(';', $stringLigne);
		
		$dom = new DOMDocument();
		$response = $dom->createElement('response');
		$dom->appendChild($response);

		$station = $dom->createElement('station');
		$attName = array('id','nom', 'x','y','type');

		$i = 0;
		foreach ($tab as $key => $value) {
			$item = $dom->createElement('item');
			$attributeName = $dom->createAttribute($attName[$i]);
			$attributeName->value = $value;

			$item->appendChild($attributeName);
			$station->appendChild($item);
			$i++;
		}
		$response->appendChild($station);
    	$xmlString = $dom->saveXML();
    	echo $xmlString;	
	}	
?>